import { ref } from 'vue'
import { getCheckFlowNodeList as getCheckFlowNodeListApi } from '@/api/basic'

/**
 * 审批流节点列表服务
 */
export default function () {
  const getCheckFlowNodeListLoading = ref(false)
  const checkFlowNodeList = ref<Array<BaseInfoAPIResponse.CheckFlowNodeListItem>>([])

  const getCheckFlowNodeList = async () => {
    try {
      getCheckFlowNodeListLoading.value = true
      const res = await getCheckFlowNodeListApi()
      getCheckFlowNodeListLoading.value = false
      if (res.data.code === 20000) {
        checkFlowNodeList.value = res.data.data.data
        return ''
      }

      return res.data.message
    } catch (e) {
      getCheckFlowNodeListLoading.value = false
      return '获取列表失败，请稍后重试'
    }
  }

  return {
    checkFlowNodeList,
    getCheckFlowNodeListLoading,
    getCheckFlowNodeList,
  }
}
